package com.anosine.gpsl.android.impl;

import com.anosine.gpsl.android.AppConstants;
import com.anosine.gpsl.android.WebConstants;
import com.anosine.gpsl.android.dao.ConsumerDao;
import com.anosine.gpsl.android.dao.FortifiedDao;
import com.anosine.gpsl.android.entity.Consumer;
import com.anosine.gpsl.android.presenter.BasePresenterActivity.OnLoadListener;
import com.anosine.gpsl.android.util.HttpRequestListener;
import com.anosine.gpsl.android.util.SendHttpUtils;
import com.anosine.gpsl.android.util.ToastHelper;
import com.google.gson.reflect.TypeToken;
import com.lidroid.xutils.http.RequestParams;
/**
 * @Title: ConsumerDaoImpl
 * @Package com.anosine.gpsl.android.impl
 * @Description: 接口实现
 * @author: sunny
 * @date: 2015-11-24
 * @version V1.0
 */
public class ConsumerDaoImpl implements ConsumerDao {
	private OnLoadListener loadListener;

	/**
	 * @Title: ConsumerDaoImpl(OnLoadListener loadListener)
	 * @Description: 构造方法，初始化对象，给loadListener赋值
	 * @param: loadListener
	 * @throws
	 */

	public ConsumerDaoImpl(OnLoadListener loadListener) {
		super();
		this.loadListener = loadListener;
	}
	/**   
	 * @Title: getConsumer(String usermd5)
	 * @Description: 设置设防（参数）
	 * @param: usermd5  登录验证串
	 * @return: 无   
	 * @throws   
	 */  
	@Override
	public void getConsumer(String usermd5) {
		RequestParams params = new RequestParams();
		params.addBodyParameter("usermd5", usermd5);
	
		SendHttpUtils sendHttp = new SendHttpUtils();
		TypeToken type = new TypeToken<Consumer>() {
		};
		String url = String.format("%1s/%2s", AppConstants.sCommonUrl,
				WebConstants.Do_GetConsumption_Action);
		sendHttp.doRequest(url, params, type, new HttpRequestListener<Consumer>() {
			/**
			 * @Title: onSuccess(String result, Login t)
			 * @Description: 解析成功做的操作
			 * @param: result json
			 * @param: t 登录的实体类
			 * @return: 无
			 * @throws
			 */
			@Override
			public void onSuccess(String result, Consumer t) {

				loadListener.onSuccess(t);

			}
			/**
			 * @Title: onFailure(String error)
			 * @Description: 解析失败做的操作
			 * @param: error 错误信息
			 * @return: 无
			 * @throws
			 */
			@Override
			public void onFailure(String error) {
				loadListener.onFailure();
				ToastHelper.toast(error);

			}
		});

	
	}
	
}
